package com.websoket.delta.controller;


import com.websoket.delta.config.WebSocketServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.Session;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@RestController
public class ChatController {


    @RequestMapping("/onlineusers")
    public List<String> onlineusers(@RequestParam("currentuser") String currentuser) {
        ConcurrentHashMap<String, Session> map = WebSocketServer.getSessionPools();

        return map.keySet().stream().filter(x -> !currentuser.equals(x)).collect(Collectors.toList());
    }

}